package application.easyui.datagrid.demo.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import application.easyui.datagrid.demo.dao.ApplicationDao;
import application.easyui.datagrid.demo.model.Application;
import application.easyui.datagrid.demo.model.ResponseResult;
import application.easyui.datagrid.demo.service.ApplicationService;

@Service
public class ApplicationServiceImpl implements ApplicationService{
	@Autowired
	private ApplicationDao applicationDao;
	

	@Override
	public Integer add(Application application) {
		return applicationDao.insert(application);
		
		
	}

	@Override
	public boolean delete(Integer id) {
		applicationDao.delete(id);
		return true;
	}

	@Override
	public boolean upload(Integer id, String name, String nation, String address, String nat, String provinces,
			BigDecimal height, BigDecimal wide, String marriage, Integer age, String type, String position,
			Integer year, String poName, String poType, String poWork, double balance, String province, String city,
			String county, String town, String onselfWork, String school, String education, String graduate,
			String major, String majors, String English, String Chinese, String Cantonese, String introduce) {
		applicationDao.modify(id, name, nation, address, nat, provinces, height, wide, marriage, age, type, position, year, poName, poType, poWork, balance, province, city, county, town, onselfWork, school, education, graduate, major, majors, English, Chinese, Cantonese, introduce);
		return true;
	}

	
	@Override
	public ResponseResult query(String name,Integer pageIndex,Integer pageSize) {
		pageIndex = pageIndex*pageSize - pageSize;
		//
		List<Application> query = applicationDao.query(name, pageIndex, pageSize);
		ResponseResult result = new ResponseResult();
		
		int count = applicationDao.count(name);
		result.setRows(query);
		result.setTotal(count);
		return result;
	}

}
